<?php

namespace app\index\controller;

use app\common\YujisoController;
use app\index\service\PurchasemanageService;

class Purchasemanage extends YujisoController
{
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        exitJson(PurchasemanageService::getList($this->param));
    }
    //详情 创建 修改
    public function create(){
        $param=$this->request->post();
        if ($this->request->isPost()) {
            $list=json_decode($param['list'],true);
            unset($param['list']);
            $param['list']=$list;
            if($this->param['id']){
                //编辑
                $res=PurchasemanageService::createHandle($param);
            }else{
                //新建
                $res=PurchasemanageService::createHandle($param);
            }
            exitJson($res);
        } else {
            //详情
            exitJson(PurchasemanageService::detail($this->param));
        }
    }
    //编辑页面返回明细
    public function detail(){
        returnJson(1,'',[],0);
    }
    //上传明细
    public function upload(){
        $param=[];
        $param['title']=['sku','数量','单价'];//必须校验头部
        $param['actionAsync']='\app\index\service\PurchasemanageService::uploadHandle';//上传数据的数据回调到service层处理
        $res=\app\common\service\ExcelLibraryService::read($param);
        exitJson($res);
    }
    //传发运单自动生成采购单
    public function createAuto(){
        exitJson(PurchasemanageService::createAuto($this->param,2));
    }

}